package com.zhdl.hardware.plc.siemens.exc;

import com.zhdl.hardware.plc.siemens.repository.SiemensPortCmdHandleDao;
import com.zhdl.hardware.plc.siemens.service.SiemensCmdSendService;
import com.zhdl.modules.tools.CommonCallback;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Primary;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ScheduledFuture;

@Slf4j
@Service("SiemensReceiveSendServiceImpl")
public class SiemensReceiveSendServiceImpl implements SiemensCmdSendService {

    @Resource
    @Qualifier("SiemensPortReceiveHandelImpl")
    private SiemensPortCmdHandleDao siemensPortCmdHandleDao;

    @Resource
    public ThreadPoolTaskScheduler taskScheduler1;

    Map<String, ScheduledFuture<?>> mapSF = new HashMap<>();
    /**
     * 读取plc寄存器值
     *
     * @param port     网口IP
     * @param address  寄存器地址
     * @param count    寄存器个数
     * @param timeout
     * @param callback 回调
     */
    @Override
    public void siemensAddressValue(String port, String address, int count, int timeout, CommonCallback<String> callback) {
//        siemensPortCmdHandleDao.raedValueByAddress(port, slaveId, address, count, callback);
    }

    @Override
    public void siemensAddressValue1(String port, String address, int count, CommonCallback<String> callback) {

    }

    @Override
    public void test(CommonCallback<String> callback) {

    }

    /**
     * 写入plc的值
     *
     * @param port    网口IP
     * @param address 寄存器地址
     * @param value   寄存器值
     */
    @Override
    public void siemensWriteValue(String port, String address, String value) {

    }

    @Override
    public void siemensWriteValues(String port, String address, String value) {

    }

    @Override
    public void siemensAddressValue(String port, String slaveId, String address, int count, int timeout, CommonCallback<String> callback) {
        siemensPortCmdHandleDao.raedValueByAddress(port, slaveId, address, count, callback);
//        taskScheduler1.scheduleWithFixedDelay(() -> {
//
//            }, timeout);
    }

    @Override
    public void siemensWriteValue(String port, String slaveId, String address, String value) {
        siemensPortCmdHandleDao.writeValueByAddress(port, slaveId, address, value);
    }

    @Override
    public void siemensWriteValues(String port, String slaveId, String address, String value) {

    }
}
